import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:meiyunapp/common/url_base.dart';

class AppImageWidget extends StatelessWidget {
  late String _url;
  late double _width, _height;

  AppImageWidget(
      {required String url, double width = 0, double height = 0, Key? key})
      : super(key: key) {
    _url = url;
    _width = width;
    _height = height;
  }

  @override
  Widget build(BuildContext context) {
    return CachedNetworkImage(
      width: _width,
      height: _height,
      imageUrl: UrlBase.getImage(_url),
        imageBuilder: (context, imageProvider) => Container(
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(5),
            image: DecorationImage(
              image: imageProvider,
              fit: BoxFit.cover,
            ),
          ),
        ),
      fit: BoxFit.fill,
      placeholder: (context, url) => const CupertinoActivityIndicator(),
      errorWidget: (context, url, error) => const Icon(Icons.error),
    );
  }
}
